package com.woniu51.order.controller;

import com.woniu.common.core.domain.AjaxResult;
import com.woniu.common.core.text.Convert;
import com.woniu51.order.domain.Order;
import com.woniu51.order.dto.OrderDto;
import com.woniu51.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author 杨光
 * @date 2022年04月08日 16:04
 */
@RestController
public class OrderController {


    @Autowired
    private OrderService orderService;

    @RequestMapping("feign/order/queryByOrderId")
    public Order queryByOrderId(@RequestParam("oid") Long oid){
        Order order = orderService.queryByOrderId(oid);
        return order;
    }

    @RequestMapping("feign/order/confirmPay")
    Integer confirmPay(@RequestParam("oid") Long oid){
        Integer  result  = orderService.confirmPay(oid);
        return result;
    }

    @RequestMapping("web/order/makeorder")
    public AjaxResult makeOrder(@RequestBody OrderDto orderDto, HttpServletRequest request){

        System.out.println(orderDto);
        Long userId = Convert.toLong(request.getHeader("userid"));
        orderDto.setUserId(userId);

        //预减库存
        orderService.checkTicketCountEnough(orderDto);

        orderService.makeOrder(orderDto);
        return AjaxResult.success();
    }
}
